package myStudent

import org.springframework.cloud.contract.spec.Contract

Contract.make {
    request {
        method 'GET'
        url value(consumer(regex('/api/myStudents/programs/\\d+/\\S+')),
                producer('/api/myStudents/programs/1/@qq'))
        headers {
            contentType(applicationJsonUtf8())
            header("id", 1)
        }
    }
    response {
        status 200
        body("""
          {
                "followers": [
                    {
                        "id": 1502,
                        "programId": 1,
                        "tutorId": 1,
                        "studentId": 1
                    }
                ],
                "searchUsers": [
                    {
                        "id": 1,
                        "username": "zhang",
                        "email": "zhang@qq.com",
                        "mobilePhone": "12345678901",
                    }
                ]
          }
        """)
        bodyMatchers {
            jsonPath('$.[*]', byType())
            jsonPath('$.followers.[*].id', byRegex(number()))
            jsonPath('$.followers.[*].programId', byRegex(number()))
            jsonPath('$.followers.[*].tutorId', byRegex(number()))
            jsonPath('$.followers.[*].studentId', byRegex(number()))
            jsonPath('$.searchUsers.[*].id', byRegex(number()))
            jsonPath('$.searchUsers.[*].username', byRegex(nonEmpty()))
            jsonPath('$.searchUsers.[*].email', byRegex(email()))
            jsonPath('$.searchUsers.[*].mobilePhone', byRegex(nonEmpty()))
        }
        headers {
            contentType(applicationJsonUtf8())
        }
    }
}